<?php
/**
 * 表单类模型
 *
 *@author hary <hary@taomee.com>
 */
class ads_project_model extends model
{
	private $ad_project_table;

	/**
	 * 构造函数
	 * @return max
	 */
	function __construct()
	{
		parent::__construct();

		$this->ad_project_table = $this->sys_conf_var[ 'table' ][ 'ad_project' ];
	}

	/**
	 * 通过key获取整个project的数据
	 * @return max
	 */
	public function getAdsProjectById($id){

		$id = $this->formatData($id);

		$this->where("p_id",$id);

		$project = $this->getDataInfo($this->ad_project_table);

		return $project;
	}

	/**
	 * 添加一个project
	 * @param $pro
	 * @return boolean
	 */
	public function addAdsProject($pro){

		$pro = $this->formatData($pro);
		
		$arr['p_name'] 		  = trim($pro['p_name']);
		$arr['p_link_email']  = trim($pro['p_link_email']);
		$arr['p_link_phone']  = trim($pro['p_link_phone']);
		$arr['p_link_man']    = trim($pro['p_link_man']);
		$arr['p_des']  		  = trim($pro['p_des']);
		$arr['sort']  		  = intval($pro['sort']);
		$arr['p_create_date'] = time();

		$this->addData($arr);

		$result = $this->dataInsert($this->ad_project_table);

		return $result;
	}

	/**
	 * 根据key删除project
	 * @return max
	 */
	public function delAdsProjectById($id){

		$id = $this->formatData($id);

		$this->where('p_id',$id);

		return $this->dataDel($this->ad_project_table);
	}

	/**
	 * 更改ads项
	 * @return boolean
	 */
	public function changeAdsProjectById($pro){

		$pro = $this->formatData($pro);

		if(!is_array($pro)) return false;

		$id = intval($pro['p_id']);

		$arr['p_name'] 		  = $pro['p_name'];
		$arr['p_link_email']  = $pro['p_link_email'];
		$arr['p_link_phone']  = $pro['p_link_phone'];
		$arr['p_link_man']    = $pro['p_link_man'];
		$arr['p_des']  		  = $pro['p_des'];
		$arr['sort']  		  = $pro['sort'];
		$arr['p_update_date'] = time();
			
		$this->addData($arr);

		$this->where('p_id',$id);

		return $this->dataUpdate($this->ad_project_table);

	}

	/**
	 * 根据关键字获取多个ads
	 * @return max
	 */
	public function getAdsProjectsByKeywords($keywords,$page='1',$page_size='10',$order='sort desc'){

		$keywords = $this->formatData($keywords);

		if(empty($keywords))
		{
			$sql = "select * from $this->ad_project_table ";
		}
		else
		{
			$sql = "select * from $this->ad_project_table where
	   				p_name like '%$keywords%' or 
	   				p_link_email like '%$keywords%' or 
	   				p_link_phone like '%$keywords%' or 
	   				p_link_man like '%$keywords%'  or 
	   				p_des like '%$keywords%'";
		}
			
		if($page) $this->setPage($page);
			
		if($page_size) $this->setLimit($page_size);
			
		if($order) $this->setOrder('order by '.$order);
			
		return $this->customQuery($sql);
	}

}